<template>
	<view class="container">
		<view class="form">
			<text class="title">账号登入</text>
			<input class="input" type="text" placeholder="请输入用户名" v-model="username" placeholder-style="color:#999" />
			<input class="input" placeholder="请输入密码" v-model="password" type="password"
				placeholder-style="color:#999" />
			<button class="btn" type="primary" @click="handleLogin">登入</button>
			<view class="link">
				<text>没有账号？</text>
				<navigator url="/pages/Register/Register" class="register-text">去注册</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		setUserInfo,
		setToken
	} from '../../utils/auth';
	export default {
		data() {
			return {
				username: '',
				password: ''
			}
		},
		methods: {
			handleLogin() {
				if (!this.username || !this.password) {
					uni.showToast({
						title: '请输入完整信息',
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					title: '登录中...'
				});
				setTimeout(() => {
					setUserInfo({
						username: this.username
					});
					setToken(`mock_token_${Date.now()}`);
					uni.hideLoading();
					uni.showToast({
						title: '登录成功'
					});
					// 跳转到我的页面tabBar路径
					uni.switchTab({
						url: "/pages/UserInfoPage/UserInfoPage"
					});
				}, 1000);
			}
		}
	};
</script>

<style scoped>
	.container {
		width: 100%;
		min-height: 100vh;
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 30rpx;
		box-sizing: border-box;
		background-color: #f8f8f8;
	}

	.form {
		width: 100%;
		max-width: 600rpx;
	}

	.title {
		display: block;
		text-align: center;
		font-size: 44rpx;
		font-weight: 600;
		color: #333;
		margin-bottom: 60rpx;
	}

	.input {
		color: #333;
		font-size: 30rpx;
		padding: 30rpx 24rpx;
		margin-bottom: 36rpx;
		border: 2rpx solid #eee;
		background-color: #fff;
		border-radius: 12rpx;
	}

	.register-text {
		color: #007aff;
		margin-left: 12rpx;
	}

	.link {
		text-align: center;
		font-size: 26rpx;
		color: #666;
	}

	.btn {
		width: 100%;
		height: 96rpx;
		font-size: 32rpx;
		border-radius: 48rpx !important;
		margin-bottom: 40rpx;
	}
</style>